//
//  RNOLQuickLoginView.m
//  RongNiuOnline
//
//  Created by apple on 2018/4/26.
//  Copyright © 2018年 rongniu. All rights reserved.
//

#import "RNOLQuickLoginView.h"

@interface RNOLQuickLoginView ()

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@property (weak, nonatomic) IBOutlet UIImageView *logoIconView;

@property (weak, nonatomic) IBOutlet UILabel *phoneMarkView;
//logo宽/高度约束
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *logoWidthConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *logoHeightConstraint;

@end


@implementation RNOLQuickLoginView

- (void)awakeFromNib{
    [super awakeFromNib];
    //设置左边圆角
    [self.phoneMarkView setCornerOnLeft:5];
    [self layoutIfNeeded];
    
    [self.loginButton setBackgroundColor: kAppMainColor forState:UIControlStateNormal];
    [self.loginButton setBackgroundColor: kTextLightGrayColor forState:UIControlStateDisabled];

    //MARK:- 监听键盘弹出
    [[kNotificationCenter rac_addObserverForName:UIKeyboardWillShowNotification object:nil] subscribeNext:^(NSNotification * _Nullable x) {
        dispatch_main_async_safe(^{
            [UIView animateWithDuration:0.25 animations:^{
                self.logoIconView.transform = CGAffineTransformMakeScale(0.8, 0.8);
                self.logoWidthConstraint.constant = 80;
                self.logoHeightConstraint.constant = 80;
                [self layoutIfNeeded];
            }];
        });
    }];
    
    //MARK:- 监听键盘消失
    [[kNotificationCenter rac_addObserverForName: UIKeyboardWillHideNotification object:nil] subscribeNext:^(NSNotification * _Nullable x) {
        dispatch_main_async_safe(^{
            [UIView animateWithDuration:0.25 animations:^{
                self.logoIconView.transform = CGAffineTransformIdentity;
                self.logoWidthConstraint.constant = 100;
                self.logoHeightConstraint.constant = 100;
                [self layoutIfNeeded];
            }];
        });
    }];
}

- (IBAction)backAction:(UIButton *)sender {
    [self endEditing:YES];
    [self.viewController.navigationController dismissViewControllerAnimated:YES completion:^{
        
    }];
}

//显示或隐藏密码
- (IBAction)displayPasswordAction:(UIButton *)sender {
    sender.selected = !sender.selected;
    self.passwordTextField.secureTextEntry = !self.passwordTextField.secureTextEntry;
}

//登录
- (IBAction)LoginAction:(UIButton *)sender {
    !self.loginActionBlock? : self.loginActionBlock();
}

//跳转注册页面
- (IBAction)skipToRegisterPageAction:(UIButton *)sender {
    !self.skipRegisterBlock? : self.skipRegisterBlock();
}

@end
